package cn.easy.mortgage.config;

import cn.easy.mobile.intercepter.ApiCommonIntercepter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Configuration
public class ApiFilterConfig extends WebMvcConfigurerAdapter {
    /**
     * 切换语言
     *
     * @return
     */
    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
        lci.setParamName("lang");
        return lci;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());

        ApiCommonIntercepter apiCommonIntercepter = new ApiCommonIntercepter();
        registry.addInterceptor(apiCommonIntercepter).addPathPatterns("/api/**");
        super.addInterceptors(registry);
    }
}
